package com.yanze.controller;

import com.yanze.pojo.TestReadResource;
import com.yanze.utils.BaseJSONResult;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class HelloController {

    @Autowired
    private TestReadResource readResource;

    @ResponseBody
    @RequestMapping("/hello")
    public String hello() {
        return "hellow SpringBoot~~~~ hellow SchoolInformation~~~~~~";
    }
    @ResponseBody
    @RequestMapping("/getResource")
    public BaseJSONResult getResource() {
        TestReadResource bean = new TestReadResource();
        BeanUtils.copyProperties(readResource, bean);
        return BaseJSONResult.ok(bean);
    }

    @RequestMapping("/index")
    public String index(ModelMap map) {
        map.addAttribute("name", "人生得意须尽欢");
        return "thymeleaf/index";
    }

    ////////////////////////异常测试
    @ResponseBody
    @RequestMapping("/testerror")
    public String testerror() {
        int a = 1 / 0;
        return "thymeleaf/error";
    }

    @RequestMapping("/ajaxerror")
    @ResponseBody
    public String ajaxerror() {
        return "thymeleaf/ajaxerror";
    }

    @RequestMapping("/getAjaxerror")
    @ResponseBody
    public BaseJSONResult getAjaxerror() {
        int a = 1 / 0;
        return BaseJSONResult.ok();
    }
}
